package com.zero.zeroframe.popup

import android.content.Context
import android.view.Gravity
import android.view.View
import com.lxj.androidktx.core.gone
import com.zero.zeroframe.R
import com.zero.zeroframe.databinding.PopupConfirmBinding
import com.zero.zeroframe.v.BasePopup

class ConfirmPopup: BasePopup<PopupConfirmBinding> {
    private var confirmListener :() -> Unit
    private var cancelListener :(() -> Unit)? = null
    private var mTtitle:String = ""
    private var mMsg:String = ""

    constructor(context: Context,title:String = "提醒", msg:String, confirmListener : () -> Unit, cancelListener :() -> Unit):super(context, R.layout.popup_confirm){
        this.mMsg = msg
        this.mTtitle = title
        this.confirmListener = confirmListener
        this.cancelListener = cancelListener
    }
    constructor(context: Context,title:String = "提醒", msg:String, confirmListener : () -> Unit):super(context, R.layout.popup_confirm){
        this.mMsg = msg
        this.mTtitle = title
        this.confirmListener = confirmListener
    }

    fun showSingle(){
        mBinding.btnCancel.gone()
        show()
    }

    override fun PopupConfirmBinding.initView() {
        popupGravity = Gravity.CENTER
        setOutSideDismiss(false)
        setBackPressEnable(false)
    }

    override fun bindView(contentView: View) {
        mBinding = PopupConfirmBinding.bind(contentView)
    }

    override fun show() {
        super.showPopupWindow()
        mBinding.tvMsg.text = mMsg
        mBinding.tvTitle.text = mTtitle
        mBinding.btnCancel.setOnClickListener {
            dismiss()
            cancelListener?.invoke()
        }
        mBinding.btnConfirm.setOnClickListener {
            dismiss()
            confirmListener.invoke()
        }
    }
}